home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0758 / setup.arv / PROCESS.TEM < prev    next >
Encoding:
Text File  |  1997-04-10  |  6.8 KB  |  211 lines

  1. #
  2. # process the order from the user
  3. # process order title
  4.         $TITLE="Order";
  5. ###############################
  6. # END OF CHANGEABLE OPTIONS   #
  7. ###############################
  8.  
  9. # START MAIN PROGRAM 
  10. # ------------------
  11.  
  12. &ReadParse;
  13. $Session = $in{'SessionID'};
  14. if    ($Session eq '')               {&PrintError; exit 1;}  # An Error
  15. elsif ($Session eq '*SeSiOnId*')     {&PrintError; exit 1;};  # Get a session id
  16.  
  17. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
  18. $mon = $mon + 1;
  19.  
  20. # $date=`date '+%m%d%y'`;
  21. $date = $mon . $mday . $year;
  22.  
  23. if (-e $date . ".ord") {
  24.         if (!open(ORDFILE, ">>" . $date . ".ord")) { &PrintError; exit 1; };
  25. } else {
  26.         if (!open(ORDFILE, ">" . $date . ".ord")) { &PrintError; exit 1; };
  27. }
  28.  
  29. print ORDFILE "$Session\n"; # needed for utilities 
  30. close(ORDFILE);
  31.  
  32. if (!open(ORDER, ">" . $Session . ".frm")) { &PrintError; exit 1; };
  33.  
  34. if (!dbmopen(%items, "$Session", 0777)) {
  35.         &PrintError;
  36.         exit 1;
  37. }
  38.  
  39. if (!dbmopen(%prices, "prices", 0777)) {
  40.         &PrintError;
  41.         exit 1;
  42. }
  43.  
  44. if ($items{'TotalOrder'} == 0) {
  45.         &PrintNothingOrdered;
  46.         exit 1;
  47. }
  48.  
  49. print "Content-Type: text/html\n\n";
  50. print "<html><head><title>$Title</title></head><body BGCOLOR=#ffffff>";
  51.  
  52. &printBoth("Order ID $Session", "<h1>", "</h1>");
  53. &printBoth("Date : $mon/$mday/$year, Time : $hour:$min", "<br>", "<br>");
  54. print ORDER "\n";
  55. &printBoth("Thank you for your order, here is a copy of the order that was processed", "<br>", "<br>");
  56. print ORDER "\n";
  57. &printCompany; # generated by CatMake
  58. print ORDER "\n";
  59. &printBoth("Please send me the following products :", "<br>", "");
  60. &printProducts; # will be generated by catmake
  61. &printShippingCharges;
  62. &printPaymentCharges;
  63. &printGrandTotal;
  64. &printPayment;
  65. &printBoth("Shipping information", "<br><B>", "</B>");
  66. &printShipping; # we got that info 
  67. &printBoth("Billing information", "<br><B>", "</B>");
  68. &printBilling; # we got that info
  69. &printContact;
  70. &printComments;
  71.  
  72. close(ORDER);
  73.  
  74. dbmclose(%items);
  75. dbmclose(%prices);
  76.  
  77. &PrintContinue; # The generator will make that 
  78.  
  79. exit(1);
  80.  
  81. # GENERAL SUBROUTINES
  82. # -------------------
  83.  
  84. sub ReadParse {
  85.   local (*in) = @_ if @_;   local ($i, $loc, $key, $val);
  86.   if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } 
  87.   elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); }
  88.   @in = split(/&/,$in);
  89.   foreach $i (0 .. $#in) {
  90.     $in[$i] =~ s/\+/ /g;
  91.     ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
  92.     $key =~ s/%(..)/pack("c",hex($1))/ge;
  93.     $val =~ s/%(..)/pack("c",hex($1))/ge;
  94.     $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
  95.     $in{$key} .= $val;
  96.   }
  97.   return 1; # just for fun
  98. } # ReadParse
  99.  
  100. sub PrintError {
  101. print("Content-Type: text/html\n\n");
  102. print <<EOF;
  103. <HTML> 
  104. <HEAD><TITLE>ERROR</TITLE></HEAD>
  105. <BODY>
  106. <H1 ALIGN=CENTER>$TITLE</H1>  <HR>
  107. An error occured in the script!
  108. <HR>
  109. EOF
  110. } # PrintError
  111.  
  112. sub printBoth {
  113.         local ($message, $before, $after) = @_;
  114.         print ORDER $message . "\n";
  115.         print $before . $message . $after;
  116. } # printBoth 
  117.  
  118. sub printShipping {
  119.         &printBoth($in{'SHIPNAME'}, "<br>", "");
  120.         &printBoth($in{'SHIPTITLE'}, "<br>", "");
  121.         &printBoth($in{'SHIPCOMPANY'}, "<br>", "");
  122.         &printBoth($in{'SHIPADDR1'}, "<br>", "");
  123.         &printBoth($in{'SHIPADDR2'}, "<br>", "");
  124.         &printBoth($in{'SHIPCITY'}, "<br>", "");
  125.         &printBoth($in{'SHIPSTATE'}, "<br>", "");
  126.         &printBoth($in{'SHIPZIP'}, "<br>", "");
  127.         &printBoth($in{'SHIPCOUNTRY'}, "<br>", "");
  128. } # printShipping
  129.  
  130. sub printBilling { 
  131.         if ($in{'BILLNAME'} eq '') {
  132.                 &printBoth("Same as shipping", "<br>", "<br>");
  133.         } else { 
  134.                 &printBoth($in{'BILLNAME'}, "<br>", "");
  135.                 &printBoth($in{'BILLTITLE'}, "<br>", "");
  136.                 &printBoth($in{'BILLCOMPANY'}, "<br>", "");
  137.                 &printBoth($in{'BILLADDR1'}, "<br>", "");
  138.                 &printBoth($in{'BILLADDR2'}, "<br>", "");
  139.                 &printBoth($in{'BILLCITY'}, "<br>", "");
  140.                 &printBoth($in{'BILLSTATE'}, "<br>", "");
  141.                 &printBoth($in{'BILLZIP'}, "<br>", "");
  142.                 &printBoth($in{'BILLCOUNTRY'}, "<br>", "");
  143.         } 
  144. } # printBilling
  145.  
  146. sub printContact {
  147.         &printBoth("Contact Information", "<B>", "</B>");
  148.         &printBoth("Tel    : " . $in{'PHONE'}, "<br>", "");
  149.         &printBoth("Fax    : " . $in{'FAX'}, "<br>", "");
  150.         &printBoth("EMail1 : " . $in{'EMAIL1'}, "<br>", "");
  151.         &printBoth("EMail2 : " . $in{'EMAIL2'}, "<br>", "");
  152. } # printContact
  153.  
  154. sub printShippingCharges {
  155.         &printBoth("Shipping Charges", "<br><b>", "</b>");
  156.         $Shipping = "S_" . $in{'SHIPOPT'};
  157.         $TotalShipping = ($prices{$Shipping . "3"} * $items{'TotalProducts'}) +
  158.                         $prices{$Shipping . "1"} + ($prices{$Shipping . "2"} * $items{'TotalWeight'});
  159.         &printBoth("Total for $in{'SHIPOPT'} : \$$TotalShipping", "<br>", "<br>");
  160. } # printShippinhCharges
  161.  
  162. sub printPayment {
  163.         &printBoth("Payment Method", "<br><b>", "</b>");
  164.         &printBoth("Payment by $in{'PAYOPT'}", "<br>", "");
  165.         if ($prices{$payment . "1"} == 1) {
  166.                 # Purchase Orders
  167.                 &printBoth("PO/WT number $in{'CARDNUM'}", "<br>", "");
  168.         } elsif ($prices{$payment . "1"} == 2) {
  169.                 # Credit Card
  170.                 &printBoth("Card number : $in{'CARDNUM'}", "<br>", "");
  171.                 &printBoth("Name on card : $in{'NAMEONCARD'}", "<br>", "");
  172.                 &printBoth("Expiration date : $in{'EXPRDATE'}", "<br>", "");
  173.         } 
  174. } # printPayment
  175.  
  176. sub printPaymentCharges {
  177.         $payment = "P_" . $in{'PAYOPT'};
  178.         $fee = $prices{$payment . "2"};
  179.         if ($fee != 0) {
  180.                 &printBoth("Payment fee is \$$fee", "<br>", "<br>");
  181.         } # there are payment fees 
  182. } # printPaymentCharges
  183.  
  184. sub printGrandTotal {
  185.         $GrandTotal = $fee + $items{'TotalOrder'} + $TotalShipping;
  186.         &printBoth("Total payment is \$$GrandTotal", "<br>", "<br>");
  187. } # printGrandTotal
  188.  
  189. sub printComments {
  190.         if (!($in{'COMMENTS'} eq '')) {
  191.                 &printBoth("Comments", "<br><b>", "</b>");
  192.                 &printBoth($in{'COMMENTS'}, "<br>", "");
  193.         }
  194. } # printComments
  195.  
  196. sub PrintNothingOrdered {
  197. print("Content-Type: text/html\n\n");
  198. print <<EOF;
  199. <HTML> 
  200. <HEAD><TITLE>Order Error</TITLE></HEAD>
  201. <BODY BGCOLOR=#ffffff>
  202. <H1 ALIGN=CENTER>Order Error</H1><HR>
  203. No products were ordered!<br>
  204. Please press the Back button, specify what products you want to
  205. order by clicking the Submit button under an item's quantity table,
  206. after you have specified the number of items in the table!
  207. <HR>
  208. EOF
  209. } # PrintNothingOrdered
  210.  
  211.